﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="HexConversionForm.cs" company="Voogd en Voogd Diensten">
//   Copyright 2008-2009 Voogd en Voogd Diensten
// </copyright>
// <author>Jelle</author>
// <summary>
//   De HexConversionForm class.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace GLCDDesigner2
{
    using System;
    using System.Collections.Generic;
    using System.Drawing;
    using System.Linq;
    using System.Reflection;
    using System.Windows.Forms;

    using GLCDBaseTypes.BaseTypes;
    using GLCDBaseTypes.PluginInterfaces;

    public partial class HexConversionForm : Form
    {
        public HexConversionForm()
        {
            InitializeComponent();

            Assembly moduleAssembly = Assembly.LoadFrom(@"C:\Users\Jelle\Documents\Visual Studio 2010\Projects\GLCDDesigner\GLCDST7565Plugin\bin\Debug\GLCDST7565Plugin.dll");

            Type[] types = moduleAssembly.GetTypes();

            foreach (var instance in
                from type in types
                where type.GetInterface("ILcdPlugin") != null
                select (ILcdPlugin)Activator.CreateInstance(type))
            {
                this.toolStripComboBox1.Items.Add(instance);
            }

            this.toolStripComboBox1.SelectedIndex = 0;
        }

        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            // Convert hex to image
            List<HexRepresentationItem> hexItems = new List<HexRepresentationItem>();
            List<string> parsedHex = richTextBox1.Text.Split(',').ToList();

            foreach (string s in parsedHex)
            {
                HexRepresentationItem hexItem = new HexRepresentationItem();
                hexItem.HexValue = s;

                hexItems.Add(hexItem);
            }

            Bitmap bmp = ((ILcdPlugin)toolStripComboBox1.SelectedItem).CreateBitmapFromHex(hexItems, Convert.ToInt32(toolStripTextBox1.Text), Convert.ToInt32(toolStripTextBox2.Text));
            pictureBoxLCDVersion.Image = bmp;
        }

        /// <summary>
        /// Copy tool strip menu item click
        /// </summary>
        /// <param name="sender">De Sender param van het type object</param>
        /// <param name="e">De E param van het type EventArgs</param>
        private void copyToolStripMenuItem_Click(object sender, EventArgs e)
        {
            richTextBox1.Copy();
        }

        /// <summary>
        /// Paste tool strip menu item click
        /// </summary>
        /// <param name="sender">De Sender param van het type object</param>
        /// <param name="e">De E param van het type EventArgs</param>
        private void pasteToolStripMenuItem_Click(object sender, EventArgs e)
        {
            richTextBox1.Paste();
        }
    }
}
